﻿<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>ReaLogic开发框架 - 登录</title>
<link href="${ctxPath}/favicon.ico" type="image/x-icon" rel="shortcut icon" />
<link href="${ctxPath}/aceAjax/css/bootstrap.css?v=3.3.6" rel="stylesheet">
<link href="${ctxPath}/aceAjax/css/login.css" rel="stylesheet">
<script type="text/javascript" src="${ctxPath}/assets/global/js/jquery.min.js?v=2.1.4"></script>
<script type="text/javascript" src="${ctxPath}/assets/global/js/jquery.form-3.51.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/global/js/plugins/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/global/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/global/js/plugins/backbone/underscore.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/global/js/plugins/backbone/backbone-min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/global/js/plugins/backbone/backbone.localStorage.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/global/js/plugins/backbone/backboneCommon.js"></script>
<script>
	if (window.top !== window.self) {
		window.top.location = window.location;
	}
</script>

<script type="text/javascript">
/*
 * type:请求类型
 * url:请求地址
 * async:是否同步
 * callback:回调函数
 * --------------------------------------------------------------------
 */
function ajaxSubmit(type,url,async,callback){
	 $.ajax({
		 	async: async,
		 	type : type,
			url : url +'?token=' + token,
			success : function (data,textStatus, res) {
				if(data.code!='000000'){
					//top.alert(data.memo);
					if (data.code== '请求参数错误'){
		      			if (data.memo == '用户未登陆，请重新登陆！'){
		      				reLogin();
						}
					} else {
						
					}
				}
				if(data.code=='010000'){
					parent.location.href = "/";
				}
				callback!=''? callback(data) : null;
			},
			error:function(){
			},
			beforeSend:function(){
				//loading('请稍等...');
			}
	 });
}; 
$(document).ready(function() {
	var ajax_option={
		type:'post',
		url:"${ctxPath}/main.do",
		success:function(data){
			if(data.code=='success'){
				var d = data.result;
				var t = new Date().getTime();
           		//d.user.token = t;                    		
				//var system = new systemModel({user:d.user,menu:d.menus,system:'工学云平台'});
				//var systemcoll = new systemCollection();
           		//systemcoll.localStorage._clear();
           		//systemcoll.create(system);
           		location.href = "${ctxPath}/home?token="+t;
			}else{
				location.href = "${ctxPath}/main.do";
			}
		}
	};
    $("#loginForm").validate({
        messages: {
        	account: {required: "请输入用户名."},
        	password: {required: "请输入密码."}
        },
        errorLabelContainer: "#messageBox",
        errorPlacement: function(error, element) {
            error.appendTo($("#loginError").parent());
        },
        submitHandler: function(form) {
        	$("#loginForm").ajaxSubmit(ajax_option);
        }
    });//validate--end
});
// 如果在框架中，则跳转刷新上级页面
if(self.frameElement && self.frameElement.tagName=="IFRAME"){
    parent.location.reload();
}
</script>

</head>

<body class="signin">
	<div class="signinpanel">
		<div class="row">
			<div class="col-sm-7">
				<div class="signin-info">
					<div class="logopanel m-b">
						<h1>[ReaLogic开发框架 ]</h1>
					</div>
					<div class="m-b"></div>
					<h4>
						欢迎使用 <strong>ReaLogic开发框架</strong>
					</h4>
					<ul class="m-b">
						<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势一</li>
						<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势二</li>
						<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势三</li>
						<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势四</li>
						<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优势五</li>
					</ul>
				</div>
			</div>
			<div class="col-sm-5">
				<form method="post" action="#" id="loginForm">
					<h4 class="no-margins">用户登录：</h4>
					<p class="m-t-md"></p>
					<input type="text" class="form-control uname required" name="account" placeholder="用户名" /> 
					<input type="password" class="form-control pword m-b required" name="password" placeholder="密码" /> 
					<button class="btn btn-success btn-block">登录</button>
					<div id="messageBox" class="alert-error" style="display:none;">
						<label id="loginError" class="error"></label>
					</div>
				</form>
			</div>
		</div>
		<div class="signup-footer">
			<div class="pull-left">&copy; 2016-2020 All Rights Reserved. K+</div>
		</div>
	</div>
</body>
</html>